import time
from tkinter import *
from DmjTool import Getdm
import threading

isend = True
def rundef(dm):#用于弹幕更新
    text = ''
    text = dm['nickname']+' 说 '+dm['text']+'\n'
    text0.config(state=NORMAL)
    text0.insert(END, text)#向Text框体中写入弹幕
    text0.see('end')#跳到text框体的最后面
    text0.config(state=DISABLED)

getdm = Getdm(47631,10,rundef)
root=Tk()
root.attributes("-alpha", 0.5)#设置半透明
root.title('弹幕姬')

def dmall():#进入获取弹幕的循环
    while isend:
        getdm.newalldm()

s1 = Scrollbar(root)
s1.pack(side = RIGHT, fill = Y)
text0 = Text (root,width=50,height=10,yscrollcommand = s1.set)#把滚动条绑定在Text上
text0.pack()
t = threading.Thread(target=dmall)#把获取弹幕的循环放入子线程
t.start()
text0.config(state=DISABLED)
root.mainloop()
isend = False
t.join
